<!--
 * @Author: Vi卡农
 * @Date: 2020-04-07 15:00:39
 * @LastEditTime: 2020-05-11 11:54:46
 * @Description: -意向单列表页-
 * @FilePath: \cshf_admin\src\views\modules\intention\intentioninfo.vue
 -->
<template>
  <el-card shadow="never" class="aui-card--fill" ref="fromc">
    <div class="mod-intention__intentioninfo}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" ref="froma">
        <el-row>
          <el-col :span="19">
            <el-form-item>
              录入日期：
              <el-date-picker
                v-model="dataForm.createDates"
                type="date"
                placeholder="开始时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
              ></el-date-picker>
              {{' -'}}
              <el-date-picker
                v-model="dataForm.createDatee"
                type="date"
                placeholder="结束时间"
                value-format="yyyy-MM-dd"
                style="width:136px"
              ></el-date-picker>
            </el-form-item>

            <el-form-item>
              部门：
              <el-cascader
                class="FormSelect"
                v-model="deptSelectVal"
                :options="this.$store.state.DeptList"
                :show-all-levels="false"
                @change="deptIdChange"
                :props="deptProps"
                ref="myCascader"
                clearable
              ></el-cascader>-
              <el-select v-model="dataForm.userId" placeholder="人员" class="FormSelect" clearable>
                <el-option
                  v-for="item in maintainList"
                  :key="item.id"
                  :label="item.realName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              交易类型：
              <ren-select
                v-model="dataForm.transactionType"
                dict-type="houseTransactionType"
                class="FormSelect"
                clearable
              ></ren-select>
            </el-form-item>
            <el-form-item>
              进度:
              <ren-select
                v-model="dataForm.state"
                dict-type="intentionState"
                class="FormSelect"
                clearable
              ></ren-select>
            </el-form-item>
            <el-form-item>
              状态：
              <ren-select
                v-model="dataForm.status"
                dict-type="intentionStatus"
                class="FormSelect"
                clearable
              ></ren-select>
            </el-form-item>
            <!-- <el-form-item>
              审核：
              <ren-select
                v-model="dataForm.examine"
                dict-type="examine"
                placeholder="审核类型"
                class="FormSelect"
              ></ren-select>
            </el-form-item>-->
            <el-form-item>
              <el-button
                v-if="$hasPermission('intention:intentioninfo:delete')"
                type="danger"
                @click="deleteHandle()"
              >{{ $t('deleteBatch') }}</el-button>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            搜索：
            <el-input
              placeholder="请输入内容"
              v-model="dataForm.search"
              class="input-with-select"
              @keyup.enter.native="getDataList"
              clearable
              style="width:70%"
            >
              <el-button slot="append" icon="el-icon-search" @click="getDataList"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        :height="autoTabHeight"
        border
        @selection-change="dataListSelectionChangeHandle"
        @row-dblclick="tableRowDbclick"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="意向单编号" header-align="center" align="center">
          <template slot-scope="scope">{{"YX - "+scope.row.id.substring(scope.row.id.length-6)}}</template>
        </el-table-column>
        <el-table-column prop="dictName" label="楼盘名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="customerName" label="客户姓名" header-align="center" align="center"></el-table-column>
        <!-- <el-table-column prop="customerId" label="客源编号" header-align="center" align="center">
          <template
            slot-scope="scope"
          >{{"KY - "+scope.row.customerId.substring(scope.row.customerId.length-6)}}</template>
        </el-table-column>
        <el-table-column prop="houseId" label="房源编号" header-align="center" align="center">
          <template
            slot-scope="scope"
          >{{"FY - "+scope.row.houseId.substring(scope.row.houseId.length-6)}}</template>
        </el-table-column>-->
        <el-table-column prop="type" label="物业类型" header-align="center" align="center">
          <template slot-scope="scope">
            <span
              :style="dictTypeColor(scope.row.type)"
            >{{ $getDictLabel("dictType", scope.row.type) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="transactionType"
          label="交易"
          header-align="center"
          align="center"
          width="70"
          sortable="custom"
        >
          <template slot-scope="scope">
            <span
              :class="scope.row.transactionType==1?'typeColor1':'typeColor2'"
            >{{ $getDictLabel("houseTransactionType", scope.row.transactionType).slice(0,1) }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="transactionType" label="交易类型" header-align="center" align="center"></el-table-column> -->
        <!--<el-table-column prop="customerType" label="客源类型" header-align="center" align="center"></el-table-column>-->

        <el-table-column prop="state" label="进度" header-align="center" align="center">
          <template slot-scope="scope">{{ $getDictLabel("intentionState", scope.row.state) }}</template>
        </el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center">
          <template slot-scope="scope">{{ $getDictLabel("intentionStatus", scope.row.status) }}</template>
        </el-table-column>
        <el-table-column prop="area" label="房源面积" header-align="center" align="center"></el-table-column>
        <el-table-column prop="price" label="价格" header-align="center" align="center"></el-table-column>
        <el-table-column
          prop="achievementCommission"
          label="佣金"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column prop="houseAgent" label="房源经纪人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="customerAgent" label="客源经纪人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="signingData" label="预计签约时间" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.signingData?scope.row.signingData.substring(0,10):scope.row.signingData}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createDate" label="录入时间" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.createDate?scope.row.createDate.substring(0,10):scope.row.createDate}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="followDate" label="跟进时间" header-align="center" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.followDate?scope.row.followDate.substring(0,10):scope.row.followDate}}</span>
          </template>
        </el-table-column>
        <!--   <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('intention:intentioninfo:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('intention:intentioninfo:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
// import AddOrUpdate from './intentioninfo-add-or-update'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/intention/intentioninfo/page",
        getDataListIsPage: true,
        deleteURL: "/intention/intentioninfo",
        deleteIsBatch: true,
      },
      dataForm: {
        id: "",
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        userId: "",
        search: "",
        transactionType: "",
        state: "",
        status: "1",
      },
      deptSelectVal: "",
      deptProps: {
        value: "id",
        label: "name",
        checkStrictly: true,
      },
      maintainList: this.$store.state.maintainList,
    };
  },
  components: {
    // AddOrUpdate
  },
  created() {
    this.$nextTick(() => {
      this.autoWidth();
    });
  },
  mounted() {
    let _this = this;
    window.onresize = function () {
      _this.autoWidth();
    };
  },
  methods: {
    autoWidth() {
      let that = this;
      let formh = that.$refs.froma.$el.offsetHeight;
      let h = that.$refs.fromc.$el.offsetHeight;
      let heightStyle = h - formh - 45;
      that.autoTabHeight = heightStyle;
    },
    deptIdChange(val) {
      let a = "";
      if (this.$refs.myCascader.getCheckedNodes()[0]) {
        a = this.$refs.myCascader.getCheckedNodes()[0].value;
        this.dataForm.deptId = a;
        this.getUserList(a);
      } else {
        this.dataForm.deptId = "";
      }
    },
    // 获取部门员工列表
    getUserList(deptId) {
      let _this = this;
      this.$http
        .get(`/sys/user/deptUserList`, {
          params: {
            deptId: deptId,
          },
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.maintainList = res.data;
        })
        .catch(() => {});
    },
    //行双击
    tableRowDbclick(row) {
      this.$router.push({
        name: "intentionPages",
        query: {
          ID: row.id,
        },
      });
    },
  },
  watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true,
    },
  },
};
</script>
<style scoped>
.typeColor1 {
  color: rgb(0, 171, 255);
}

.typeColor2 {
  color: red;
}
</style>
